/**
 * 
 */
package org.softTank.BC.service.services;

import java.util.ArrayList;
import java.util.List;

import org.softTank.BC.entity.services.Category;
import org.softTank.BC.entity.services.MessageType;
import org.softTank.BC.entity.services.Operation;
import org.softTank.BC.entity.services.PartnerLinkType;
import org.softTank.BC.entity.services.Role;
import org.softTank.BC.entity.services.Type;
import org.softTank.BC.rs.bean.CategoryBean;
import org.softTank.BC.rs.bean.MessageTypeBean;
import org.softTank.BC.rs.bean.OperationBean;
import org.softTank.BC.rs.bean.PartnerLinkTypeBean;
import org.softTank.BC.rs.bean.RoleBean;
import org.softTank.BC.rs.bean.TypeBean;

/**
 * @author Yuzone
 *
 */
public class BeanPackager {

	public static TypeBean getTypeBean(Type value) {
		if (value == null)
			return null;
		TypeBean tb = new TypeBean();
		tb.setId(value.getId());
		tb.setIsBranch("true");
		tb.setKey(value.getKey());
		tb.setName(value.getName());
		List<Category> l = value.getCategoryList();
		List<CategoryBean> list = new ArrayList<CategoryBean>();
		if (l != null) {
			for (Category c : l) {
				list.add(getCategoryBean(c));
			}
		}
		tb.setCategory(list);

		return tb;
	}

	public static CategoryBean getCategoryBean(Category value) {
		if (value == null)
			return null;
		CategoryBean cb = new CategoryBean();
		cb.setId(value.getId());
		cb.setIsBranch("true");
		cb.setKey(value.getKey());
		cb.setName(value.getName());
		List<PartnerLinkType> l = value.getPartnerLinkTypeList();
		List<PartnerLinkTypeBean> list = new ArrayList<PartnerLinkTypeBean>();
		if (l != null) {
			for (PartnerLinkType plt : l) {
				list.add(getPartnerLinkTypeBean(plt));
			}
		}
		cb.setPartnerLinkType(list);

		return cb;
	}

	public static PartnerLinkTypeBean getPartnerLinkTypeBean(
			PartnerLinkType value) {
		if (value == null)
			return null;
		PartnerLinkTypeBean pltb = new PartnerLinkTypeBean();
		pltb.setId(value.getId());
		pltb.setIsBranch("true");
		pltb.setName(value.getName());
		List<Role> l = value.getRoleList();
		List<RoleBean> list = new ArrayList<RoleBean>();
		if (l != null) {
			for (Role r : l) {
				list.add(getRoleBean(r));
			}
		}
		pltb.setRole(list);

		return pltb;
	}

	public static RoleBean getRoleBean(Role value) {
		if (value == null)
			return null;
		RoleBean rb = new RoleBean();
		rb.setId(value.getId());
		rb.setIsBranch("true");
		rb.setName(value.getName());
		rb.setPortType(value.getPortType().getName());
		List<Operation> l = value.getPortType().getOperationList();
		List<OperationBean> list = new ArrayList<OperationBean>();
		if (l != null) {
			for (Operation o : l) {
				list.add(getOperationBean(o));
			}
		}
		rb.setOperation(list);

		return rb;
	}

	public static OperationBean getOperationBean(Operation value) {
		if (value == null)
			return null;
		OperationBean ob = new OperationBean();
		// ob.setId(value.getId());
		ob.setFault(getMessageTypeBean(value.getFault()));
		ob.setInput(getMessageTypeBean(value.getInput()));
		ob.setIsBranch("true");
		ob.setName(value.getName());
		ob.setOutput(getMessageTypeBean(value.getOutput()));

		return ob;
	}

	public static MessageTypeBean getMessageTypeBean(MessageType value) {
		if (value == null)
			return null;
		MessageTypeBean mtb = new MessageTypeBean();
		mtb.setId(value.getId());
		mtb.setName(value.getName());

		return mtb;
	}
}
